package com.fire.control.system.module.device.controller.web;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.fire.control.system.dto.UserDTO;
import com.fire.control.system.module.common.controller.BaseController;
import com.fire.control.system.module.device.service.GatewayService;
import com.fire.control.system.standard.BusinessInterfaceStandard;
import com.fire.control.system.support.protocol.comman.ResponseProtocol;
import com.fire.control.system.support.protocol.device.DeviceRequestProtocol;


/**
 * 
 * @ClassName:  GatewayController
 * @Description:  网关管理控制器
 * @author:  xiechengguang
 * @date:  2017年6月27日 下午8:12:07
 *
 */
@RestController
@RequestMapping(value="/web/gateway")
public class GatewayController extends BaseController implements BusinessInterfaceStandard<DeviceRequestProtocol,ResponseProtocol>{
	private static final Logger logger = LoggerFactory.getLogger(GatewayController.class);
	@Autowired 
	private GatewayService gatewayService;
	
	
	
	/**
	 * 
	 * @Title: getGatewayList   
	 * @Description: 获取网关列表  
	 * @param:  requestProtocol     
	 * @return: ResponseProtocol      
	 * @throws
	 */
	@RequestMapping(value="/getGatewayList", method=RequestMethod.POST)
	@ResponseBody
	public ResponseProtocol getGatewayList(DeviceRequestProtocol requestProtocol) {
		logger.info("getGatewayList (" + requestProtocol.getTaskuuid() + ") task In time: "+System.currentTimeMillis());
		UserDTO user = getUser();
		ResponseProtocol response = gatewayService.getGatewayList(requestProtocol, user);
		logger.info("getGatewayList (" + requestProtocol.getTaskuuid() + ") task Out time: "+System.currentTimeMillis());
		return response;
	}
	
	/**
	 * 
	 * @Title: getGatewayInfo   
	 * @Description: 获取网关详细信息  
	 * @param:  requestProtocol      
	 * @return: ResponseProtocol      
	 * @throws
	 */
	@RequestMapping(value="/getGatewayInfo", method=RequestMethod.POST)
	@ResponseBody
	public ResponseProtocol getGatewayInfo(DeviceRequestProtocol requestProtocol) {
		
		return gatewayService.getGatewayInfo(requestProtocol);
	}
	
	/**
	 * 
	 * @Title: updateGatewayInfo   
	 * @Description: 修改网关信息  
	 * @param:  requestProtocol      
	 * @return: ResponseProtocol      
	 * @throws
	 */
	@RequestMapping(value="/updateGatewayInfo", method=RequestMethod.POST)
	@ResponseBody
	public ResponseProtocol updateGatewayInfo(DeviceRequestProtocol requestProtocol) {
		
		return gatewayService.updateGatewayInfo(requestProtocol);
	}
	
	/**
	 * 
	 * @Title: deleteGateway   
	 * @Description: 删除一个或一组网关  
	 * @param:  requestProtocol     
	 * @return: ResponseProtocol      
	 * @throws
	 */
	@RequestMapping(value="/deleteGateway", method=RequestMethod.POST)
	@ResponseBody
	public ResponseProtocol deleteGateway(DeviceRequestProtocol requestProtocol) {
		
		return gatewayService.deleteGateway(requestProtocol);
	}
	
	/**
	 * 
	 * @Title: searchGateways   
	 * @Description: 按条件搜索网关列表  
	 * @param:  requestProtocol      
	 * @return: ResponseProtocol      
	 * @throws
	 */
	@RequestMapping(value="/searchGateways", method=RequestMethod.POST)
	@ResponseBody
	public ResponseProtocol searchGateways(DeviceRequestProtocol requestProtocol) {
		UserDTO user = getUser();
		return gatewayService.searchGateways(requestProtocol, user);
	}
	
	/**
	 * 
	 * @Title: addGateway   
	 * @Description: 新增网关  
	 * @param:  requestProtocol      
	 * @return: ResponseProtocol      
	 * @throws
	 */
	@RequestMapping(value="/addGateway", method=RequestMethod.POST)
	@ResponseBody
	public ResponseProtocol addGateway(DeviceRequestProtocol requestProtocol) {
		
		return gatewayService.addGateway(requestProtocol);
	}
	
	/**
	 * 
	 * @Title: getGatewaysByTreeId   
	 * @Description: 根据省、市、区、设备组获取其下的对应网关
	 * @param:  requestProtocol      
	 * @return: ResponseProtocol      
	 * @throws
	 */
	@RequestMapping(value="/getGatewaysByTreeId", method=RequestMethod.POST)
	@ResponseBody
	public ResponseProtocol getGatewaysByTreeId(DeviceRequestProtocol requestProtocol) {
		return gatewayService.getGatewaysByTreeId(requestProtocol, getUser());
	}
	
}
